﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TM.Common.Extensions
{
    public static class DateExt
    {
        public static int ToSQLiteDateTime(this DateTime dateTime)
        {
            var dtime = new DateTime(1970, 1, 1);
            var dt = (dateTime - dtime).TotalSeconds;
            return (int)dt;
        }

        public static int ToSQLiteDateTime(this System.Nullable<DateTime> dateTime)
        {
            if (dateTime.HasValue)
            {
                var dtime = new DateTime(1970, 1, 1);
                var dt = (dateTime.Value - dtime).TotalSeconds;
                return (int)dt;
            }

            return 0;
        }

        /// <summary>
        /// Get default of start working time: 8h00 AM
        /// </summary>
        /// <param name="dateTime"></param>
        /// <returns></returns>
        public static DateTime StartOfToday(this DateTime dateTime)
        {
            return new DateTime(dateTime.Year, dateTime.Month, dateTime.Day,
                                8, 0, 0);
        }
    }
}
